package com.zhiyou100.api.packing_demo;

import java.io.IOException;
import java.util.Arrays;

public class Demo1 {

    public static void main(String[] args) throws IOException {
//        box();
//        testSystem();
        testMillis();
    }

    public static void testMillis(){
        //获取开始时间    以毫秒值为单位
        long start = System.currentTimeMillis();
        System.out.println("start = " + start);
        for (int i = 0; i < 100000000; i++) {
            int m = i;
        }
        long end = System.currentTimeMillis();
        System.out.println("end = " + end);
        System.out.println(end - start);
    }


    public static void testArrayCopy() {
        char[] src = {'A', 'B', 'C', 'd'};
        char[] dest = {'x', 'y', 'z', 'j'};
        //数组的复制
        System.arraycopy(src, 1, dest, 1, 2);
        System.out.println(Arrays.toString(dest));
    }


    public static void testSystem() throws IOException {
//        Scanner scanner = new Scanner(System.in);
        //读取从键盘输入的字符
        System.out.println("请输入字符：以回车为结束标志");
        //利用System.in读取数据，每次读取一个
        int i = System.in.read();
        while (i != '\r') {
            char c = (char) i;
            System.out.println("c = " + c);
            i = System.in.read();
        }
    }


    public static void testNumber() {
        //以多态的形式表示Number
        Number number = new Double("56.8");
        int i = number.intValue();
        System.err.println("i = " + i);
        long l = number.longValue();
        System.err.println("l = " + l);
        float v = number.floatValue();
        System.err.println("v = " + v);
    }


    //Integer包装类
    public static void testInteger() {
        //以int变量作为形参创建Integer对象
        Integer integer1 = new Integer(108);
        System.out.println("integer1 = " + integer1);
        //需要将一个字符串类型的数字转换成Integer数据
        String s = "108";
        Integer integer2 = new Integer(s);
        System.out.println("integer2 = " + integer2);
        //拆箱
        int i = integer2;
        System.out.println("i = " + i);
        //将一个字符串类型的整数转换成int类型
        int j = Integer.parseInt(s);
        System.out.println("j = " + j);
        //将一个字符串类型的整数转换成Integer类型
        Integer integer3 = Integer.valueOf("789");
        System.out.println("integer3 = " + integer3);  //789
        Integer integer4 = Integer.valueOf("100", 2);
        System.out.println("integer4 = " + integer4);
        //比较两个integer类型的对象
        int z = integer2.compareTo(integer3);
        System.out.println("z = " + z);
        //判断相等
        boolean b = integer1.equals(integer2);
        System.out.println("b = " + b);
        //将Integer类型的额数据转成String
        String s1 = integer1.toString();
        System.out.println("s1 = " + s1);

        //将Integer转换成int类型
        int y = integer2;
        int m = integer2.intValue();
        //进制转换
        //二进制
        String s2 = Integer.toBinaryString(m);
        System.out.println("s2 = " + s2);
        //十六进制
        String s3 = Integer.toHexString(m);
        System.out.println("s3 = " + s3);
        //八进制
        String s4 = Integer.toOctalString(m);
        System.out.println("s4 = " + s4);

        //int转字符串
        String s5 = Integer.toString(80);
        String s6 = 80 + "";
    }


    //装箱:将基本数据类型转换成包装类类型
    public static void box() {

        int i = 500;
        //赋值给了Integer类型的变量   装箱   系统自动完成的
        Integer obj = i;
        System.out.println("obj = " + obj);  //500
        //拆箱  系统自动完成
        int m = obj;
        System.out.println("m = " + m); //500

        Integer obj2 = 500;
        //equals的比较已被Integer重写，比较的是数据
        System.out.println(obj.equals(obj2));
    }


}
